package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.common.utils.MD5Util;
import com.atguigu.lease.model.entity.SystemUser;
import com.atguigu.lease.web.admin.mapper.SystemUserMapper;
import com.atguigu.lease.web.admin.service.SystemUserService;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserItemVo;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserQueryVo;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【system_user(员工信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {

    @Autowired
    private SystemUserMapper systemUserMapper;

    @Override
    public void customPage(Page<SystemUserItemVo> page, SystemUserQueryVo queryVo) {
        systemUserMapper.customSelectPage(page, queryVo);
    }

    @Override
    public SystemUserItemVo customGetById(Long id) {
        return systemUserMapper.customSelectById(id);
    }

    @Override
    public boolean customSaveOrUpdate(SystemUser systemUser) {

        //判断密码参数是否为空，若为空，则赋null，原因：前端传值有问题，传过来的是空字符串，不是空，会覆盖数据的密码数据
        if (!ObjectUtils.isEmpty(systemUser.getPassword())) {
            systemUser.setPassword(DigestUtils.md5Hex(systemUser.getPassword()));
        }
//        else {
//            systemUser.setPassword(null);
//        }

        //执行添加或修改
        return saveOrUpdate(systemUser);
    }
}




